<template>
    <div>
        <el-card>
            <div>
                <el-form :model="form" ref="ruleForm" style="width: 100%">
                    <el-row :gutter="20">
                        <el-col :span="5">
                            <el-form-item label="项目名称">
                                <el-select
                                    style="width: 100%"
                                    placeholder="请选择项目"
                                    v-model="projectName"
                                    @change="handleSelectProject"
                                >
                                    <el-option
                                        v-for="(project, idx) in projectList"
                                        :key="idx"
                                        :label="project.project_name_"
                                        :value="project"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-button type="primary" size="mini" @click="getData">查询</el-button>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </el-card>
        <el-card>
            <div class="baseCss">
                <el-button type="primary" size="mini" @click="handleAddData">添加</el-button>
            </div>
            <el-table :data="tableData" border>
                <el-table-column type="index" label="序号" width="50" align="center" />
                <el-table-column label="项目编码" prop="project_no_" align="center"></el-table-column>
                <el-table-column label="项目名称" prop="project_name_" align="center"></el-table-column>
                <el-table-column label="施工段名称" align="center">
                    <template #default="scope">
                        <div>{{ scope.row.construction_index_ ? (scope.row.construction_index_ + '-' + scope.row.construction_name_) : '-' }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="制单人" prop="create_user_" align="center"></el-table-column>
                <el-table-column label="制单时间" prop="create_time_" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template #default="scope">
                        <el-button type="text" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button type="text" @click="handleSearch(scope.$index, scope.row)">详情</el-button>
                        <el-button type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
export default {
    data() {
        return {
            projectId: '',
            projectNo: '',
            projectName: '',
            projectList: [],
            shareList: [],
            selectShare: '',
            tableData: [],
            jobDataList: [],
            typeWork: '',
            user: '',
        }
    },
    created() {
        this.getProjectList()
        this.getData()
    },
    methods: {
        // 查询项目列表
        getProjectList() {
            const param = { curPage: 1, pageSize: 10000, params: {} }
            this.$axios.post(`/form/formCustSql/view/list_ppcgSecondaryScheduleMst`, param).then(res => {
                if (res.isOk) {
                    this.projectList = res.data.list
                } else {
                    this.$ElMessage({
                        message: res.msg,
                        type: 'error',
                    })
                }
            })
        },
        // 选择项目
        handleSelectProject(item) {
            this.projectId = item.project_id_
            this.projectName = item.project_name_
            this.projectNo = item.project_no_
        },
        getData() {
            this.loading = true
            let param = { curPage: 1, pageSize: 10, params: { queryData: [{ name: "project_no_", con: "=", val: this.projectNo }] } }
            this.$axios.post(`/form/formCustSql/view/list_ppcgSecondaryScheduleMst`, param).then(res => {
                if (res.isOk) {
                    this.loading = false
                    this.tableData = res.data.list
                    this.tableData.map(item => {
                        if (item.create_time_) {
                            item.create_time_ = this.$moment(item.create_time_).format('YYYY-MM-DD HH:mm:ss')
                        }
                    })
                } else {
                    this.$ElMessage({
                        message: res.msg,
                        type: 'error',
                    })
                }
            })
        },
        handleAddData() {
            this.$router.push({ path: `/createSecondarySchedule` });
        },
        handleEdit(index, row) {
            this.$router.push({ path: `/secondaryScheduleDtl&${row.id_}&false` })
        },
        handleSearch(index, row) {
            this.$router.push({ path: `/secondaryScheduleDtl&${row.id_}&true` })
        },
        handleDelete(index, row) {
            this.$ElMessageBox.confirm(
                '确定删除该条数据吗？',
                '警告',
                {
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            ).then(() => {
                this.$axios.post(`/form/formDefData/removeData/ppcgSecondaryScheduleMst/${row.id_}`).then(res => {
                    if (res.isOk) {
                        this.$ElMessage({
                            message: '删除成功',
                            type: 'success',
                        })
                        this.getData()
                    } else {
                        this.$ElMessage({
                            message: res.msg,
                            type: 'error',
                        })
                    }
                })
            }).catch(() => {
            })
        }
    }
}
</script>

<style scoped>
.el-tabs__content {
    padding: 0 !important;
}
.btn-margin {
    margin-left: 0;
}
.btn-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.baseCss {
    text-align: left;
    margin-bottom: 1rem;
}
</style>